//
//  NativeExpressAdViewController.m
//  HZZFAdSDK_Example
//
//  Copyright © 2025 早范. All rights reserved.
//

#import "NativeExpressAdViewController.h"
#import <HZZFAdSDK/HZZFAdSDKNativeExpressAd.h>
#import <HZZFAdSDK/HZZFAdSDKAdapter.h>
#import <HZZFAdSDK/HZZFUtilsKit.h>
@interface NativeExpressAdViewController ()<HZZFAdSDKNativeExpressAdDelegate>
@property (nonatomic) HZZFAdSDKNativeExpressAd *nativeExpressAd;
@end

@implementation NativeExpressAdViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"信息流模版";
    self.view.backgroundColor = [UIColor whiteColor];
    CGFloat width = (self.view.frame.size.width - 150) / 2;
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(width, 150, 150, 40);
    
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    btn.backgroundColor = [UIColor orangeColor];
    btn.layer.cornerRadius = 20;
    [self.view addSubview:btn];
    [btn setTitle:@"显示广告" forState:UIControlStateNormal];
//    [btn setTitleColor:[UIColor blackColor] forState:0];
    [btn addTarget:self action:@selector(innerLoadNativeExpressAd) forControlEvents:UIControlEventTouchUpInside];
}

- (void) innerLoadNativeExpressAd {
    if (!self.nativeExpressAd) {
        UIWindow *window = [UIApplication sharedApplication].keyWindow;
        UIViewController *rvc = window.rootViewController;
        
        self.nativeExpressAd = [[HZZFAdSDKNativeExpressAd alloc] initWithAdSize:CGSizeMake(self.view.frame.size.width, 10)];
        self.nativeExpressAd.delegate = self;
        self.nativeExpressAd.controller = rvc;
        self.nativeExpressAd.posId = @"99908725";
    }
    
//    [[BwtAdLogManager getBwtAdLogManager] log:@"正在加载信息流模板广告, adId: %@", _adParams.adId];
    [self.nativeExpressAd load:1];
}

#pragma mark - HZZFAdSDKNativeExpressAdDelegate
/**
 信息流广告请求成功

 @param nativeAd 广告实例
 @param adViewArray 广告模板集合
 */
- (void)HZZF_nativeAdSucessToLoad:(HZZFAdSDKNativeExpressAd *)nativeAd
                     adViewArray:(NSArray<__kindof UIView<HZZFAdapterNativeExpressAdViewDelegate> *> *)adViewArray{
    for (UIView<HZZFAdapterNativeExpressAdViewDelegate> *adView in adViewArray) {
        [adView render];
        CGSize adViewSize = adView.bounds.size;
        adView.frame = CGRectMake(0, 250, adViewSize.width, adViewSize.height);
        [self.view addSubview:adView];
    }
}

/**
 信息流广告请求失败

 @param nativeAd 广告实例
 @param error 请求错误描述
 */
- (void)HZZF_nativeAdFailToLoad:(HZZFAdSDKNativeExpressAd *)nativeAd
                         error:(NSError *)error{
    NSString *message = [error localizedDescription];
    
  
}

/**
 信息流广告渲染成功

 @param adView 广告视图
 */
- (void)HZZF_nativeAdViewRenderOrRegistSuccess:(UIView<HZZFAdapterNativeExpressAdViewDelegate> *)adView{
 
}

/**
 信息流广告渲染失败

 @param adView 广告视图
 */
- (void)HZZF_nativeAdViewRenderOrRegistFail:(UIView<HZZFAdapterNativeExpressAdViewDelegate> *)adView{
    NSString *message = @"广告渲染失败了";
    

}

/**
 信息流广告被点击

 @param nativeAd 广告模板
 */
- (void)HZZF_nativeAdClicked:(HZZFAdSDKNativeExpressAd *)nativeAd
                     adView:(__kindof UIView<HZZFAdapterNativeExpressAdViewDelegate> *)adView loadingPageURL:(NSString *)loadingPageURL{

}

/**
 信息流广告被关闭
 
 @param nativeAd 广告模板
 */
- (void)HZZF_nativeAdClose:(HZZFAdSDKNativeExpressAd *)nativeAd
                   adView:(__kindof UIView<HZZFAdapterNativeExpressAdViewDelegate> *)adView{

}

/**
 信息流广告被展示
 
 @param nativeAd 广告实例
 */
- (void)HZZF_nativeAdExposure:(HZZFAdSDKNativeExpressAd *)nativeAd
                      adView:(__kindof UIView<HZZFAdapterNativeExpressAdViewDelegate> *)adView{

}

/**
 信息流广告落地页被关闭
 
 @param nativeAd 广告实例
 */
- (void)HZZF_nativeAdCloseLandingPage:(HZZFAdSDKNativeExpressAd *)nativeAd
                              adView:(__kindof UIView<HZZFAdapterNativeExpressAdViewDelegate> *)adView{
    
}

@end
